<!-- 列表 -->
<template>
	<view class="list">
		<view class="list-item" v-for="item in list" :key="item.id" @click="handleNavToDetailPage(item.id)">
			<view class="header">
				<image class="icon" src="/pagesC-my/static/images/ask.svg" mode="widthFix"></image>
				<text class="title">{{item.title}}</text>
			</view>
			<view class="body">
				<image class="icon" src="/pagesC-my/static/images/answer.svg" mode="widthFix"></image>
				<text class="title" v-if="item.reply && item.reply[0]">{{item.reply[0].content}}</text>
				<text class="title light" v-else>暂无回答</text>
			</view>
			<view class="footer">
				<text class="label">浏览({{item.views}})</text>
				<text class="label">回复({{item.replies}})</text>
				<text class="label">{{item.create_time}}</text>
			</view>
		</view>
		
		<!-- 暂无数据 -->
		<c-empty-data v-if="!list.length && !loadingState.default"></c-empty-data>
		<!-- loading -->
		<view style="margin-top: 20rpx;">
			<c-loading :loadingState="loadingState"></c-loading>
		</view>
	</view>

</template>

<script setup>
	import { storeToRefs } from 'pinia';
	import { useMyAskStore } from "../store.js";

	const { list, loadingState } = storeToRefs(useMyAskStore());

	// 跳转到详情页
	const handleNavToDetailPage = (id) => {
		uni.navigateTo({
			url: '/pagesC-my/ask-detail/index?id=' + id
		});
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 32rpx 25rpx;

		&-item {
			height: 210rpx;
			padding: 26rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-sizing: border-box;

			&:active {
				background-color: #f8f8f8;
			}

			&+.list-item {
				margin-top: 25rpx;
			}

			.header {
				display: flex;
				align-items: center;

				.icon {
					flex-shrink: 0;
					width: 32rpx;
					height: 32rpx;
				}

				.title {
					flex-grow: 1;
					width: 0;
					font-weight: 500;
					font-size: 28rpx;
					color: #222222;
					line-height: 1.5;
					padding-left: 10rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}

			.body {
				display: flex;
				align-items: center;
				margin-top: 16rpx;

				.icon {
					flex-shrink: 0;
					width: 32rpx;
					height: 32rpx;
				}

				.title {
					flex-grow: 1;
					width: 0;
					font-weight: 500;
					font-size: 28rpx;
					color: #222222;
					line-height: 1.5;
					padding-left: 10rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					
					&.light {
						color: #aaa;
					}
				}
			}

			.footer {
				display: flex;
				align-items: center;
				margin-top: 28rpx;

				.label {
					font-size: 24rpx;
					color: #999999;

					&+.label {
						margin-left: 32rpx;
					}
				}
			}
		}
	}
</style>